/**
 * 
 */
package monitor;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JPanel;

/**
 * @Description:  
 * @version: v1.0.0
 * @author: wbl
 * @date: 2019年10月23日 下午5:17:58
 */
public class GD extends JPanel{
	int height = 500;
	int y = height-40;

	void scroll() {
		ArrayList<String> arrayList = new ArrayList<>();
		try {
	
			FileReader fr = new FileReader("C:\\Users\\19391\\Desktop\\Java课程设计\\select.txt");//把这个地址换为你想要读入的文本文件地址**
			BufferedReader bf = new BufferedReader(fr);
			String str;
			// 按行读取字符串
			while ((str = bf.readLine()) != null) {
				arrayList.add(str);
			}
			bf.close();
			fr.close();
		} 
	catch (IOException e) {
			e.printStackTrace();
		}
		// 对ArrayList中存储的字符串进行处理
		int length = arrayList.size();int n=length;
		String[] headlines = new String[length];
		for (int i = 0; i < length; i++) {
			headlines[i]= arrayList.get(i);
		}
	    while (true) {
	        y = y - 1;
	        if (y < -headlines.length*20)//如果到了窗口底部
	            y = height-40;
	        repaint();//重绘窗口
	        try {
	            Thread.sleep(20);
	        } catch (InterruptedException e) { }
	    }
	} 
	public void paintComponent(Graphics comp) {
		ArrayList<String> arrayList = new ArrayList<>();
		try {
	
			FileReader fr = new FileReader("C:\\Users\\19391\\Desktop\\Java课程设计\\select.txt");//把这个地址换为你想要读入的文本文件地址
			BufferedReader bf = new BufferedReader(fr);
			String str;
			// 按行读取字符串
			while ((str = bf.readLine()) != null) {
				arrayList.add(str);
			}
			bf.close();
			fr.close();
		} 
	catch (IOException e) {
			e.printStackTrace();
		}
		// 对ArrayList中存储的字符串进行处理
		int length = arrayList.size();int n=length;
		String[] headlines = new String[length];
		for (int i = 0; i < length; i++) {
			headlines[i]= arrayList.get(i);
		}
	    Graphics2D comp2D = (Graphics2D)comp;
	    Font type = new Font("楷体", Font.BOLD, 20);//字体对象
	    GradientPaint gp=new GradientPaint(0,0,Color.yellow,0,getSize().height,Color.white,false);//背景颜色渐变（黄-->白）
	    comp2D.setFont(type);//设置字体
	    comp2D.setPaint(gp);
	    GradientPaint gp2=new GradientPaint(0,0,Color.blue,0,getSize().height,Color.orange,false);//字体颜色渐变（橙-->蓝）
	    comp2D.fillRect(0, 0, getSize().width, getSize().height);
	    comp2D.setPaint(gp2);
	    for (int i = 0; i < headlines.length; i++)//设置每一行字的位置
	        comp2D.drawString(headlines[i], 100, y + (20 * i));
	}
	
	
	
	
}
